<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->

<template>
  <div
    class="Home"
    v-loading="loading"
    element-loading-text="加载业务数据 ... ..."
  >
    <div class="taskBacklog">
      <div class="taskBacklog_title">
        <img src="@/pages/pc/assets/taskBacklogImg.png" alt="" />
        <span class="title">待办任务</span>
        <!--<i class="el-icon-refresh" @click="loadData"></i>-->
        <el-button type="text" icon="el-icon-refresh" @click="loadData"></el-button>
      </div>
      <div class="taskBacklog_content">
        <div
          class="taskBacklog_content_item"
          v-for="(item, index) in toDo"
          :key="index"
        >
          <div class="taskBacklog_content_item_left">
            <img :src="taskBacklogQueryImg(item.busiTypeId)" alt="" />
          </div>
          <div class="taskBacklog_content_item_content">
            <span>{{ item.busiTypeName }}</span>
            <el-button type="text" @click="particularsGo(item)">{{ item.messageContent }}</el-button>
            <p>{{ item.creationTs | dateFormat }}</p>
          </div>
          <div class="taskBacklog_content_item_right">
            <button @click="particularsGo(item)">详情</button>
          </div>
        </div>
      </div>

      <div class="taskBacklog_font">
        <button @click="moreGo">去往任务中心查看更多</button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";

export default {
  name: "HomePageNeedWork",
  data () {
    return {
      loading: true,
      pieIndex: "",
      pieId: "23",
      toDo: []
    };
  },
  mounted () {
    // 查询业务数据 // TODO 延迟2秒，模拟查询业务数据的过程
    this.loadData();
  },
  computed: {
    ...mapState(["applets"])
  },

  methods: {
    // 加载图标
    taskBacklogQueryImg (id) {
      return (
        this.$baseUrl +
        "/joys-rest/joys-file/file/browse/one2one/" +
        id +
        "?AUTH-TOKEN=" +
        localStorage.getItem("AUTH-TOKEN")
      );
    },
    // 查看更多
    moreGo () {
      var params = {
        appletId: 103030
      };
      this.$bus.sendMessage("OPEN_APPLET", params);
    },
    // 跳转详情方法
    particularsGo (row) {
      var params = {
        appletId: row.formId,
        taskId: row.taskId,
        busiDataId: row.busiId
      };
      this.$bus.sendMessage("OPEN_APPLET", params);
      this.changeMessageStatus(row)
    },
      // 更改任务状态为已读
      changeMessageStatus(value) {
          console.log(value.messageStatus)
          if (value.messageStatus !== 'READ') {
              value.messageStatus = 'READ'
              const url = '/joys-rest/joys-bpm/taskMessage';
              this.$http.put(url, value).then(resp => {
                  this.value = resp.data
              }).catch(resp => {
                  this.$message.error(resp.response.data.message)
              })
          }
      },
    // 模拟查询业务数据
    loadData () {
      this.toDo = []
      this.$http
        .get("/joys-rest/joys-bpm/taskMessage/byCondition", {
          params: {
            pageIndex: 1,
            pageSize: 3
          }
        })
        .then(resp => {
          this.toDo = resp.data.rows;
          console.log(this.toDo, '')
          this.loaded();
        })
        .catch(err => {
          this.$message.error(err.response.data.message);
        });
    },
    // TODO 业务数据查询完毕后,并且页面渲染完毕后，取消加载动画
    loaded () {
      this.$nextTick(() => {
        //渲染完毕
        this.loading = false;
      });
    },
    topCheck (ind) {
      let appletId = this.top[ind].appletId;
      // this.openApplet({appletId});
      var params = { appletId: appletId };
      this.$bus.sendMessage("OPEN_APPLET", params);
    },

    // 联查
    taskClick (item) {
      // this.openApplet(item)
      // var params = {appletId: appletId}
      this.$bus.sendMessage("OPEN_APPLET", item);
    },

    ...mapActions(["openApplet"])
  }
};
</script>

<style scoped lang="less">
.Home {
  padding: 0px 0px 0px 0px;
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
  i {
    color: #979797;
  }
  .taskBacklog {
    width: 100%;
    height: 100%;
    background: #fff;
    position: relative;
    .taskBacklog_title {
      height: 63px;
      display: flex;
      align-items: center;
      margin: 0 24px;
      border-bottom: 1px solid #e5e8f3;
      box-sizing: border-box;
      img {
        width: 32px;
        margin-right: 16px;
      }
      i{
        margin-left: 10px;
        font-size: 18px;
        cursor: pointer;
      }
      button {
        font-size: 18px;
      }
    }
    .taskBacklog_content {
      margin: 0 24px;
      margin-top: 12px;
      .taskBacklog_content_item {
        height: 60px;
        width: 100%;
        overflow: hidden;
        display: flex;
        align-items: center;

        .taskBacklog_content_item_left {
          float: left;
          width: 24px;
          height: 24px;
          img {
            width: 24px;
            height: 24px;
          }
        }
        .taskBacklog_content_item_right {
          float: right;
          position: absolute;
          right: 24px;
          button {
            width: 54px;
            height: 24px;
            border: 1px solid #b3baca;
            border-radius: 12px;
            background: #fff;
            font-family: PingFangSC-Regular;
            font-size: 14px;
            color: #8a8e98;
            letter-spacing: 0.47px;
          }
          button:hover {
            background: #eee;
            cursor: pointer;
          }
          button:focus {
            outline: none;
            color: #000;
          }
        }
        .taskBacklog_content_item_content {
          margin-left: 27px;
          span {
            font-family: PingFangSC-Regular;
            font-size: 14px;
            color: #3d3d3d;
            letter-spacing: 0.36px;
            font-weight: 700;
          }
          i {
            font-style: normal;
            font-family: PingFangSC-Regular;
            font-size: 14px;
            color: #8a8e98;
            letter-spacing: 0.36px;
            margin: 0 24px;
          }
          button {
            font-style: normal;
            font-family: PingFangSC-Regular;
            font-size: 14px;
            /*color: #595959;*/
            letter-spacing: 0.36px;
            /*font-weight: 700;*/
          }
          em:hover {
            /*background: #eee;*/
          }
          p {
            margin-top: 6px;
            font-family: Helvetica;
            font-size: 12px;
            color: #b6bcd0;
            letter-spacing: 0;
          }
        }
      }
    }
    .taskBacklog_font {
      position: absolute;
      left: 50%;
      margin-left: -90px;
      bottom: 24px;
      text-align: center;
      button {
        width: 180px;
        height: 34px;
        background: #fff;
        border: 1px solid #b3baca;
        border-radius: 1px;
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #8a8e98;
        letter-spacing: 0.47px;
      }
      button:hover {
        background: rgb(240, 238, 238);
      }
      button:focus {
        outline: none;
        color: #000;
      }
    }
  }
}
</style>
